home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Code Resources / Eclectic CDEFs / CDEFTester Folder / CDEFTesterDemo.p < prev    next >
Text File  |  1997-03-05  |  17KB  |  593 lines

  1. {    CDEF Collection Demo    }
  2. {}
  3. {    Main program for demonstrating the CDEF Collection    }
  4. {}
  5. {    Copyright © Sebastiano Pilla 1996    }
  6. {    All rights reserved    }
  7.  
  8. {    <mailto:case@tvol.it>    }
  9.  
  10. {    Note: This code is for demonstrational purposes only. It is probably the ugliest code I ever wrote; on the    }
  11. {    other hand, I whipped up in about 4 hours an example of all the techniques needed to use the StubCDEF and JumpCDEF    }
  12. {    "fake" defprocs.    }
  13.  
  14. program CDEFCollectionDemo;
  15.  
  16.  
  17.     uses
  18.         Controls, CelsiusCDEFStub, StubCDEFIntf, GaussCDEFStub, JumpCDEFIntf, MovableModal;
  19.  
  20.  
  21.     const
  22.         rCelsiusDemoDialogID = 128;
  23.  
  24.         kRunCelsiusDemoItem = 1;
  25.         kToggleCelsiusItemsItem = 2;
  26.         kFirstCelsiusControlItem = 3;
  27.         kLastCelsiusControlItem = 18;
  28.         kExitCelsiusDemoItem = 29;
  29.  
  30.  
  31.     const
  32.         kCelsiusCtlMin = 0;
  33.         kCelsiusCtlMax = 200;
  34.  
  35.  
  36.     procedure DoCelsiusCDEFDemo;
  37.         var
  38.             theRect: Rect;
  39.             savePort: GrafPtr;
  40.             theHandle: Handle;
  41.             theDialog: DialogPtr;
  42.             junk: SInt32;
  43.             theControls: array[kFirstCelsiusControlItem..kLastCelsiusControlItem] of ControlHandle;
  44.             theItem, j, theType, val: SInt16;
  45.             hilited: Boolean;
  46.     begin
  47.         GetPort(savePort);
  48.         theDialog := GetNewDialog(rCelsiusDemoDialogID, nil, WindowPtr(-1));
  49.         if theDialog = nil then
  50.             Exit(DoCelsiusCDEFDemo);
  51.         for j := kFirstCelsiusControlItem to kLastCelsiusControlItem do
  52.             begin
  53.                 GetDialogItem(theDialog, j, theType, theHandle, theRect);
  54.                 theControls[j] := ControlHandle(theHandle);
  55.                 junk := AttachRealCDEFUPP(ControlDefProcPtr(@CelsiusCDEF), theControls[j]);
  56.                 SetControlMinimum(theControls[j], kCelsiusCtlMin);
  57.                 SetControlMaximum(theControls[j], kCelsiusCtlMax);
  58.                 SetControlValue(theControls[j], kCelsiusCtlMin);
  59.                 HiliteControl(theControls[j], kControlNoPart);
  60.             end;
  61.         hilited := true;
  62.         ShowWindow(theDialog);
  63.         SelectWindow(theDialog);
  64.         SetPort(theDialog);
  65.         DrawDialog(theDialog);
  66.         theItem := 0;
  67.         while theItem <> kExitCelsiusDemoItem do
  68.             begin
  69.                 MovableModalDialog(nil, theItem);
  70.                 case theItem of
  71.                     kRunCelsiusDemoItem: 
  72.                         begin
  73.                             SetCursor(GetCursor(watchCursor)^^);
  74.                             for val := kCelsiusCtlMin to kCelsiusCtlMax do
  75.                                 for j := kFirstCelsiusControlItem to kLastCelsiusControlItem do
  76.                                     SetControlValue(theControls[j], val);
  77.                             for j := kFirstCelsiusControlItem to kLastCelsiusControlItem do
  78.                                 SetControlValue(theControls[j], 0);
  79.                             SetCursor(arrow);
  80.                         end;
  81.                     kToggleCelsiusItemsItem: 
  82.                         begin
  83.                             if hilited then
  84.                                 begin
  85.                                     for j := kFirstCelsiusControlItem to kLastCelsiusControlItem do
  86.                                         HiliteControl(theControls[j], kControlInactivePart);
  87.                                     hilited := false;
  88.                                 end
  89.                             else
  90.                                 begin
  91.                                     for j := kFirstCelsiusControlItem to kLastCelsiusControlItem do
  92.                                         HiliteControl(theControls[j], kControlNoPart);
  93.                                     hilited := true;
  94.                                 end;
  95.                         end;
  96.                     otherwise
  97.                         ;
  98.                 end;
  99.             end;
  100.         for j := kFirstCelsiusControlItem to kLastCelsiusControlItem do
  101.             junk := RemoveRealCDEFUPP(theControls[j]);
  102.         DisposeDialog(theDialog);
  103.         SetPort(savePort);
  104.     end;
  105.  
  106.  
  107.     const
  108.         rGaussDemoDialogID = 129;
  109.  
  110.         kToggleGaussItemsItem = 1;
  111.         kExitGaussDemoItem = 2;
  112.  
  113.         kGaussControlUserItem = 3;
  114.  
  115.         kDrawTitleOnlyRadioBtnItem = 4;
  116.         kDrawTitleAndValueRadioBtnItem = 5;
  117.         kDrawValueOnlyRadioBtnItem = 6;
  118.         kDrawTextFromRefConRadioBtnItem = 7;
  119.  
  120.         kAlignLeftRadioBtnItem = 8;
  121.         kAlignCenterRadioBtnItem = 9;
  122.         kAlignRightRadioBtnItem = 10;
  123.         kFullJustRadioBtnItem = 11;
  124.  
  125.         kUseWFontCheckItem = 12;
  126.         kDrawBoundsRectCheckItem = 13;
  127.         kDoNotDimCheckItem = 14;
  128.         kDraw3DEffectCheckItem = 15;
  129.         kUseStdColorsCheckItem = 16;
  130.  
  131.         rTitlesStrListID = 128;
  132.         kTitleOnlyIndex = 1;
  133.         kTitleAndValueIndex = 2;
  134.  
  135.  
  136.     type
  137.         FunctionalSpecs = packed array[kDrawTitleOnlyRadioBtnItem..kDrawTextFromRefConRadioBtnItem] of SInt8;
  138.         AlignmentSpecs = packed array[kAlignLeftRadioBtnItem..kFullJustRadioBtnItem] of SInt8;
  139.         AppearanceSpecs = packed array[kUseWFontCheckItem..kUseStdColorsCheckItem] of SInt8;
  140.  
  141.  
  142.     procedure InitDialogButtons (inDialog: DialogPtr;
  143.                                     var outFuncSpecs: FunctionalSpecs;
  144.                                     var outAlignSpecs: AlignmentSpecs;
  145.                                     var outAppearSpecs: AppearanceSpecs);
  146.         var
  147.             theRect: Rect;
  148.             theHandle: Handle;
  149.             i, theType: SInt16;
  150.     begin
  151.         outFuncSpecs[kDrawTitleOnlyRadioBtnItem] := 1;
  152.         for i := kDrawTitleAndValueRadioBtnItem to kDrawTextFromRefConRadioBtnItem do
  153.             outFuncSpecs[i] := 0;
  154.         outAlignSpecs[kAlignLeftRadioBtnItem] := 1;
  155.         for i := kAlignCenterRadioBtnItem to kFullJustRadioBtnItem do
  156.             outAlignSpecs[i] := 0;
  157.         for i := kUseWFontCheckItem to kUseStdColorsCheckItem do
  158.             outAppearSpecs[i] := 0;
  159.         for i := kDrawTitleOnlyRadioBtnItem to kDrawTextFromRefConRadioBtnItem do
  160.             begin
  161.                 GetDialogItem(inDialog, i, theType, theHandle, theRect);
  162.                 SetControlValue(ControlHandle(theHandle), outFuncSpecs[i]);
  163.             end;
  164.         for i := kAlignLeftRadioBtnItem to kFullJustRadioBtnItem do
  165.             begin
  166.                 GetDialogItem(inDialog, i, theType, theHandle, theRect);
  167.                 SetControlValue(ControlHandle(theHandle), outAlignSpecs[i]);
  168.             end;
  169.         for i := kUseWFontCheckItem to kUseStdColorsCheckItem do
  170.             begin
  171.                 GetDialogItem(inDialog, i, theType, theHandle, theRect);
  172.                 SetControlValue(ControlHandle(theHandle), outAppearSpecs[i]);
  173.             end;
  174.     end;
  175.  
  176.  
  177.     const
  178.         kGaussMinimumCtlMax = 128;
  179.  
  180.         kGaussEffectThreshold = -100;
  181.  
  182.         kDrawTitleAndValueVarCodeMask = $1;
  183.         kDrawValueOnlyVarCodeMask = $2;
  184.         kDrawTextFromRefConVarCodeMask = $4;
  185.         kUseWindowFontVarCodeMask = $8;
  186.  
  187.         kDrawBoundingRectangleExtVarCodeMask = $100;
  188.         kNeverDimControlExtVarCodeMask = $200;
  189.         kDraw3DEffectExtVarCodeMask = $400;
  190.         kUseStdColorsExtVarCodeMask = $800;
  191.  
  192.         rJumpCDEFID = 128;
  193.  
  194.         rTextID = 128;
  195.  
  196.  
  197.     function CreateGaussDemoControl (inDialog: DialogPtr;
  198.                                     inFuncSpecs: FunctionalSpecs;
  199.                                     inAlignSpecs: AlignmentSpecs;
  200.                                     inAppearSpecs: AppearanceSpecs;
  201.                                     inEffect: SInt16;
  202.                                     inHilited: boolean): ControlHandle;
  203.         var
  204.             theTitle: Str255;
  205.             theRect: Rect;
  206.             theHandle: Handle;
  207.             theControl: ControlHandle;
  208.             theRefCon: SInt32;
  209.             theType, theAlign, theMin, theMax, theVarCode: SInt16;
  210.     begin
  211.         theControl := nil;
  212.         CreateGaussDemoControl := nil;
  213.         GetDialogItem(inDialog, kGaussControlUserItem, theType, theHandle, theRect);
  214.         if inFuncSpecs[kDrawTitleOnlyRadioBtnItem] = 1 then
  215.             GetIndString(theTitle, rTitlesStrListID, kTitleOnlyIndex)
  216.         else if inFuncSpecs[kDrawTitleAndValueRadioBtnItem] = 1 then
  217.             GetIndString(theTitle, rTitlesStrListID, kTitleAndValueIndex)
  218.         else
  219.             theTitle := '';
  220.         if inAlignSpecs[kAlignLeftRadioBtnItem] = 1 then
  221.             theAlign := teJustLeft
  222.         else if inAlignSpecs[kAlignCenterRadioBtnItem] = 1 then
  223.             theAlign := teJustCenter
  224.         else if inAlignSpecs[kAlignRightRadioBtnItem] = 1 then
  225.             theAlign := teJustRight
  226.         else if inAlignSpecs[kFullJustRadioBtnItem] = 1 then
  227.             theAlign := ntbJustFull;
  228.         theMin := kGaussEffectThreshold;
  229.         if inAppearSpecs[kDraw3DEffectCheckItem] = 1 then
  230.             theMin := inEffect;
  231.         theMax := kGaussMinimumCtlMax;
  232.         if inAppearSpecs[kDrawBoundsRectCheckItem] = 1 then
  233.             theMax := theMax + kDrawBoundingRectangleExtVarCodeMask;
  234.         if inAppearSpecs[kDoNotDimCheckItem] = 1 then
  235.             theMax := theMax + kNeverDimControlExtVarCodeMask;
  236.         if inAppearSpecs[kDraw3DEffectCheckItem] = 1 then
  237.             theMax := theMax + kDraw3DEffectExtVarCodeMask;
  238.         if inAppearSpecs[kUseStdColorsCheckItem] = 1 then
  239.             theMax := theMax + kUseStdColorsExtVarCodeMask;
  240.         theVarCode := 0;
  241.         if inFuncSpecs[kDrawTitleAndValueRadioBtnItem] = 1 then
  242.             theVarCode := theVarCode + kDrawTitleAndValueVarCodeMask;
  243.         if inFuncSpecs[kDrawValueOnlyRadioBtnItem] = 1 then
  244.             theVarCode := theVarCode + kDrawValueOnlyVarCodeMask;
  245.         if inFuncSpecs[kDrawTextFromRefConRadioBtnItem] = 1 then
  246.             theVarCode := theVarCode + kDrawTextFromRefConVarCodeMask;
  247.         if inAppearSpecs[kUseWFontCheckItem] = 1 then
  248.             theVarCode := theVarCode + kUseWindowFontVarCodeMask;
  249.         if inFuncSpecs[kDrawTextFromRefConRadioBtnItem] = 1 then
  250.             begin
  251.                 theHandle := GetResource('TEXT', rTextID);
  252.                 if theHandle = nil then
  253.                     Exit(CreateGaussDemoControl);
  254.                 theRefCon := SInt32(theHandle);
  255.             end
  256.         else
  257.             theRefCon := BOR(Random, BSL(Random, 16));
  258.         theControl := NewControl(inDialog, theRect, theTitle, false, theAlign, theMin, theMax, (16 * rJumpCDEFID) + theVarCode, theRefCon);
  259.         if theControl <> nil then
  260.             begin
  261.                 if inHilited then
  262.                     HiliteControl(theControl, kControlNoPart)
  263.                 else
  264.                     HiliteControl(theControl, kControlInactivePart);
  265.                 ShowControl(theControl);
  266.             end;
  267.         CreateGaussDemoControl := theControl;
  268.     end;
  269.  
  270.  
  271.     function DoFunctionalSpecsClick (inDialog: DialogPtr;
  272.                                     inItemClicked, inFirstItemInRange, inLastItemInRange: SInt16): FunctionalSpecs;
  273.         var
  274.             theRect: Rect;
  275.             theHandle: Handle;
  276.             i, theType: SInt16;
  277.             theFuncSpecs: FunctionalSpecs;
  278.     begin
  279.         for i := inFirstItemInRange to inLastItemInRange do
  280.             begin
  281.                 GetDialogItem(inDialog, i, theType, theHandle, theRect);
  282.                 if i = inItemClicked then
  283.                     theFuncSpecs[i] := 1
  284.                 else
  285.                     theFuncSpecs[i] := 0;
  286.                 SetControlValue(ControlHandle(theHandle), theFuncSpecs[i]);
  287.             end;
  288.         DoFunctionalSpecsClick := theFuncSpecs;
  289.     end;
  290.  
  291.  
  292.     function DoAlignmentSpecsClick (inDialog: DialogPtr;
  293.                                     inItemClicked, inFirstItemInRange, inLastItemInRange: SInt16;
  294.                                     var outVal: SInt16): AlignmentSpecs;
  295.         var
  296.             theRect: Rect;
  297.             theHandle: Handle;
  298.             i, theType: SInt16;
  299.             theAlignSpecs: AlignmentSpecs;
  300.     begin
  301.         for i := inFirstItemInRange to inLastItemInRange do
  302.             begin
  303.                 GetDialogItem(inDialog, i, theType, theHandle, theRect);
  304.                 if i = inItemClicked then
  305.                     theAlignSpecs[i] := 1
  306.                 else
  307.                     theAlignSpecs[i] := 0;
  308.                 SetControlValue(ControlHandle(theHandle), theAlignSpecs[i]);
  309.             end;
  310.         case inItemClicked of
  311.             kAlignLeftRadioBtnItem: 
  312.                 outVal := teJustLeft;
  313.             kAlignCenterRadioBtnItem: 
  314.                 outVal := teJustCenter;
  315.             kAlignRightRadioBtnItem: 
  316.                 outVal := teJustRight;
  317.             kFullJustRadioBtnItem: 
  318.                 outVal := ntbJustFull;
  319.         end;
  320.         DoAlignmentSpecsClick := theAlignSpecs;
  321.     end;
  322.  
  323.  
  324.     procedure DoAppearanceSpecsClick (inDialog: DialogPtr;
  325.                                     inItemClicked, inFirstItemInRange, inLastItemInRange: SInt16;
  326.                                     var ioAppearSpecs: AppearanceSpecs);
  327.         var
  328.             theRect: Rect;
  329.             theHandle: Handle;
  330.             i, theType: SInt16;
  331.     begin
  332.         if ioAppearSpecs[inItemClicked] = 1 then
  333.             begin
  334.                 ioAppearSpecs[inItemClicked] := 0;
  335.                 if (inItemClicked = kDrawBoundsRectCheckItem) and (ioAppearSpecs[kDraw3DEffectCheckItem] = 1) then
  336.                     ioAppearSpecs[kDraw3DEffectCheckItem] := 0;
  337.             end
  338.         else if ioAppearSpecs[inItemClicked] = 0 then
  339.             begin
  340.                 ioAppearSpecs[inItemClicked] := 1;
  341.                 if (inItemClicked = kDraw3DEffectCheckItem) and (ioAppearSpecs[kDrawBoundsRectCheckItem] = 0) then
  342.                     ioAppearSpecs[kDrawBoundsRectCheckItem] := 1;
  343.             end;
  344.         for i := inFirstItemInRange to inLastItemInRange do
  345.             begin
  346.                 GetDialogItem(inDialog, i, theType, theHandle, theRect);
  347.                 SetControlValue(ControlHandle(theHandle), ioAppearSpecs[i]);
  348.             end;
  349.     end;
  350.  
  351.  
  352.     procedure DoGaussCDEFDemo;
  353.         var
  354.             theDialog: DialogPtr;
  355.             savePort: GrafPtr;
  356.             theControl: ControlHandle;
  357.             theNum, theEffect, theVal: SInt16;
  358.             err: OSErr;
  359.             theFuncSpecs: FunctionalSpecs;
  360.             theAlignSpecs: AlignmentSpecs;
  361.             theAppearSpecs: AppearanceSpecs;
  362.             hilited: Boolean;
  363.     begin
  364.         GetPort(savePort);
  365.         theDialog := GetNewDialog(rGaussDemoDialogID, nil, WindowPtr(-1));
  366.         if theDialog = nil then
  367.             Exit(DoGaussCDEFDemo);
  368.         err := InstallCDEFUPP(@GaussCDEF);
  369.         hilited := true;
  370.         SetPort(theDialog);
  371.         GetFNum('Geneva', theNum);
  372.         TextFont(theNum);
  373.         TextSize(9);
  374.         TextFace([bold]);
  375.         InitDialogButtons(theDialog, theFuncSpecs, theAlignSpecs, theAppearSpecs);
  376.         ShowWindow(theDialog);
  377.         SelectWindow(theDialog);
  378.         theEffect := kGaussEffectThreshold;
  379.         theControl := CreateGaussDemoControl(theDialog, theFuncSpecs, theAlignSpecs, theAppearSpecs, theEffect, hilited);
  380.         if theControl = nil then
  381.             begin
  382.                 DisposeDialog(theDialog);
  383.                 Exit(DoGaussCDEFDemo);
  384.             end;
  385.         DrawDialog(theDialog);
  386.         theNum := 0;
  387.         while theNum <> kExitGaussDemoItem do
  388.             begin
  389.                 MovableModalDialog(nil, theNum);
  390.                 case theNum of
  391.                     kToggleGaussItemsItem: 
  392.                         if hilited then
  393.                             begin
  394.                                 HiliteControl(theControl, kControlInactivePart);
  395.                                 hilited := false;
  396.                             end
  397.                         else
  398.                             begin
  399.                                 HiliteControl(theControl, kControlNoPart);
  400.                                 hilited := true;
  401.                             end;
  402.                     kGaussControlUserItem: 
  403.                         begin
  404.                             theEffect := GetControlMinimum(theControl);
  405.                             if theEffect < kGaussEffectThreshold then
  406.                                 theEffect := kGaussEffectThreshold
  407.                             else if theEffect = kGaussEffectThreshold then
  408.                                 theEffect := kGaussEffectThreshold + 1
  409.                             else if theEffect > kGaussEffectThreshold then
  410.                                 theEffect := kGaussEffectThreshold - 1;
  411.                             SetControlMinimum(theControl, theEffect);
  412.                         end;
  413.                     kDrawTitleOnlyRadioBtnItem..kDrawTextFromRefConRadioBtnItem: 
  414.                         begin
  415.                             DisposeControl(theControl);
  416.                             theFuncSpecs := DoFunctionalSpecsClick(theDialog, theNum, kDrawTitleOnlyRadioBtnItem, kDrawTextFromRefConRadioBtnItem);
  417.                             theControl := CreateGaussDemoControl(theDialog, theFuncSpecs, theAlignSpecs, theAppearSpecs, theEffect, hilited);
  418.                         end;
  419.                     kAlignLeftRadioBtnItem..kFullJustRadioBtnItem: 
  420.                         begin
  421.                             theAlignSpecs := DoAlignmentSpecsClick(theDialog, theNum, kAlignLeftRadioBtnItem, kFullJustRadioBtnItem, theVal);
  422.                             SetControlValue(theControl, theVal);
  423.                         end;
  424.                     kUseWFontCheckItem..kUseStdColorsCheckItem: 
  425.                         begin
  426.                             DisposeControl(theControl);
  427.                             DoAppearanceSpecsClick(theDialog, theNum, kUseWFontCheckItem, kUseStdColorsCheckItem, theAppearSpecs);
  428.                             theControl := CreateGaussDemoControl(theDialog, theFuncSpecs, theAlignSpecs, theAppearSpecs, theEffect, hilited);
  429.                         end;
  430.                     otherwise
  431.                         ;
  432.                 end;
  433.             end;
  434.         DisposeDialog(theDialog);
  435.         SetPort(savePort);
  436.     end;
  437.  
  438.  
  439.     const
  440.         kNumMenus = 3;
  441.  
  442.  
  443.     const
  444.         rAppleMenuID = 128;
  445.         kAppleMenuIndex = 1;
  446.         kAboutItem = 1;
  447.  
  448.         rFileMenuID = 129;
  449.         kFileMenuIndex = 2;
  450.         kQuitItem = 1;
  451.  
  452.         rDemosMenuID = 130;
  453.         kDemosMenuIndex = 3;
  454.         kCelsiusCDEFDemoItem = 1;
  455.         kGaussCDEFDemoItem = 2;
  456.  
  457.         rAboutAlertID = 128;
  458.  
  459.  
  460.     var
  461.         gMenus: array[1..kNumMenus] of MenuHandle;
  462.         gInx: SInt16;
  463.         gDoneFlag: Boolean;
  464.         gTheEvent: EventRecord;
  465.  
  466.  
  467.     procedure DoMenuCommand (inCommand: SInt32);
  468.         var
  469.             daName: Str255;
  470.             theMenu, theItem, junk: SInt16;
  471.     begin
  472.         if inCommand = 0 then
  473.             Exit(DoMenuCommand);
  474.         theMenu := HiWord(inCommand);
  475.         theItem := LoWord(inCommand);
  476.         case theMenu of
  477.             rAppleMenuID: 
  478.                 if theItem = kAboutItem then
  479.                     junk := Alert(rAboutAlertID, nil)
  480.                 else
  481.                     begin
  482.                         GetMenuItemText(GetMenuHandle(rAppleMenuID), theItem, daName);
  483.                         junk := OpenDeskAcc(daName);
  484.                     end;
  485.             rFileMenuID: 
  486.                 if theItem = kQuitItem then
  487.                     gDoneFlag := true;
  488.             rDemosMenuID: 
  489.                 case theItem of
  490.                     kCelsiusCDEFDemoItem..kGaussCDEFDemoItem: 
  491.                         begin
  492.                             DisableItem(gMenus[kAppleMenuIndex], kAboutItem);
  493.                             DisableItem(gMenus[kFileMenuIndex], 0);
  494.                             DisableItem(gMenus[kDemosMenuIndex], 0);
  495.                             DrawMenuBar;
  496.                             if theItem = kCelsiusCDEFDemoItem then
  497.                                 DoCelsiusCDEFDemo
  498.                             else if theItem = kGaussCDEFDemoItem then
  499.                                 DoGaussCDEFDemo;
  500.                             EnableItem(gMenus[kAppleMenuIndex], kAboutItem);
  501.                             EnableItem(gMenus[kFileMenuIndex], 0);
  502.                             EnableItem(gMenus[kDemosMenuIndex], 0);
  503.                             DrawMenuBar;
  504.                         end;
  505.                     otherwise
  506.                         ;
  507.                 end;
  508.             otherwise
  509.                 ;
  510.         end;
  511.         HiliteMenu(0);
  512.         DrawMenuBar;
  513.     end;
  514.  
  515.  
  516.     procedure DoMouseEvent (inEvent: EventRecord);
  517.         var
  518.             thePoint: Point;
  519.             theWindow: WindowPtr;
  520.             thePart: SInt16;
  521.     begin
  522.         thePoint := inEvent.where;
  523.         thePart := FindWindow(thePoint, theWindow);
  524.         case thePart of
  525.             inMenuBar: 
  526.                 DoMenuCommand(MenuSelect(thePoint));
  527.             inSysWindow: 
  528.                 SystemClick(inEvent, theWindow);
  529.             otherwise
  530.                 ;
  531.         end;
  532.     end;
  533.  
  534.  
  535.     procedure DoKeyEvent (inEvent: EventRecord);
  536.         var
  537.             theChar: Char;
  538.     begin
  539.         if BAND(inEvent.modifiers, cmdKey) <> 0 then
  540.             DoMenuCommand(MenuKey(Chr(BAND(inEvent.message, charCodeMask))));
  541.     end;
  542.  
  543.  
  544.     procedure DoUpdateEvent (inEvent: EventRecord);
  545.     begin
  546.         BeginUpdate(WindowPtr(inEvent.message));
  547.         EndUpdate(WindowPtr(inEvent.message));
  548.     end;
  549.  
  550.  
  551.     procedure DoActivateEvent (inEvent: EventRecord);
  552.     begin
  553.     end;
  554.  
  555.  
  556. {$I-}
  557. begin
  558.     InitGraf(@thePort);
  559.     InitFonts;
  560.     InitWindows;
  561.     InitMenus;
  562.     TEInit;
  563.     InitDialogs(nil);
  564.     InitCursor;
  565.     FlushEvents(everyEvent, 0);
  566.  
  567.     gDoneFlag := false;
  568.  
  569.     gMenus[kAppleMenuIndex] := GetMenu(rAppleMenuID);
  570.     AppendResMenu(gMenus[kAppleMenuIndex], 'DRVR');
  571.     gMenus[kFileMenuIndex] := GetMenu(rFileMenuID);
  572.     gMenus[kDemosMenuIndex] := GetMenu(rDemosMenuID);
  573.     for gInx := 1 to kNumMenus do
  574.         InsertMenu(gMenus[gInx], 0);
  575.     DrawMenuBar;
  576.  
  577.     while not gDoneFlag do
  578.         begin
  579.             if WaitNextEvent(everyEvent, gTheEvent, MaxInt, nil) then
  580.                 case gTheEvent.what of
  581.                     mouseDown: 
  582.                         DoMouseEvent(gTheEvent);
  583.                     keyDown, keyUp, autoKey: 
  584.                         DoKeyEvent(gTheEvent);
  585.                     updateEvt: 
  586.                         DoUpdateEvent(gTheEvent);
  587.                     activateEvt: 
  588.                         DoActivateEvent(gTheEvent);
  589.                     otherwise
  590.                         ;
  591.                 end;
  592.         end;
  593. end.